const { exec, escape } = require("../db/mysql");
const { genPassword } = require("../utils/cryp");

/**
 * 登录数据
 * @param {*} username
 * @param {*} password
 */
const login = (username, password) => {
  username = escape(username);
  password = genPassword(password); // 加密
  password = escape(password);
  // escape 不需要字符串包裹 '${username}'
  console.log(username);
  console.log(password);
  const sql = `
  select username, realname from users where username=${username} and password=${password}
`;
  return exec(sql).then((rows) => {
    return rows[0] || {};
  });
};

module.exports = {
  login,
};
